web/src/pages/[...section].astro
286 lines · 8270 bytes
1---
2
3
4import Layout from '@layouts/Layout.astro';
5import Button from '@components/form/Button.astro';
6import Main from '@components/scafold/MainCard.astro';
7import ServiceList from '@components/things/ServiceList.astro';
8import type { AwesomePrivacy, Section, Service, ShortService } from '../types/Service';
9import { fetchData, slugify } from '@utils/fetch-data';
10import { parseMarkdown } from '@utils/parse-markdown';
11
12interface Props {
13 slug: string,
14 title: string,
15 services: Service[],
16 intro?: string,
17 notableMentions?: ShortService[] | string,
18 furtherInfo?: string,
19 wordOfWarning?: string,
20 alternativeTo?: string[];
21 categoryName: string,
22 otherSections: Section[],
23}
24
25const {
26 title, otherSections, services, notableMentions, furtherInfo, wordOfWarning,
27 alternativeTo, categoryName, intro,
28} = Astro.props;
29
30/**
31 * Make a list of keywords, for the <meta keywords> tag
32 */
33const makeKeyWordTag = () => {
34 const keywords = [];
35 keywords.push(`free and open source ${title} software`);
36 keywords.push(`private ${title} comparison`);
37 (alternativeTo || []).forEach((alt: string) => {
38 keywords.push(`privacy-respecting ${alt} alternative`);
39 keywords.push(`free open source ${alt} alternative`);
40 });
41 (services || []).forEach((serv: Service) => {
42 keywords.push(serv.name);
43 });
44 keywords.push('ad free');
45 keywords.push('open source software');
46 keywords.push('privacy respecting apps');
47 return keywords.join(', ');
48};
49
50/**
51 * Make a page title
52 */
53const makePageTitle = () => {
54 return `${title} | Awesome Privacy`;
55};
56
57const makeBreadcrumbs = () => {
58 return [
59 { name: 'Home', item: '/' },
60 { name: categoryName, item: slugify(categoryName) },
61 { name: title, item: `${slugify(categoryName)}/${slugify(title)}` },
62 ];
63};
64
65/**
66 * Make a string page intro, for the description tag
67 */
68const makeDescriptionTag = () => {
69 let description = `Privacy respecting ${title}. `;
70 if (services && services.length > 0) {
71 const serviceList = services.map((serv: Service) => serv.name);
72 description += `Compare ${serviceList.join(' vs ')} and more private, open source apps and services now. `
73 } else {
74 description += `Find private apps and services. This section is still a work in progress. `;
75 }
76 if (alternativeTo && alternativeTo.length > 0) {
77 description += `The best secure encrypted alternatives to ${alternativeTo.join(', ')} in 2024. `;
78 }
79 description += 'All this, and many more free and awesome tools and software.'
80 return description;
81};
82
83const makeCarasolData = () => {
84 return {
85 "@context": "https://schema.org",
86 "@type": "ItemList",
87 "itemListElement": [
88 services.map((service, index) => ({
89 "@type": "ListItem",
90 "position": index + 1,
91 "url": `https://awesome-privacy.xyz/${slugify(categoryName)}/${slugify(title)}/${slugify(service.name)}`,
92 "item": {
93 "@type": "Service",
94 "name": service.name,
95 "description": service.description,
96 "image": service.icon,
97 "url": `https://awesome-privacy.xyz/${slugify(categoryName)}/${slugify(title)}/${slugify(service.name)}`
98 }
99 })),
100 ]
101 }
102};
103
104export async function getStaticPaths() {
105 const pages = await fetchData().then((data) => {
106 const results: Array<Props> = [];
107 if (!data || !data.categories) return results;
108 (data as AwesomePrivacy).categories.forEach((category) => {
109 const sections = category.sections.map((section) => ({
110 slug: `${slugify(category.name)}/${slugify(section.name)}`,
111 title: section.name,
112 services: section.services,
113 intro: section.intro,
114 notableMentions: section.notableMentions,
115 furtherInfo: section.furtherInfo,
116 wordOfWarning: section.wordOfWarning,
117 alternativeTo: section.alternativeTo,
118 categoryName: category.name,
119 otherSections: category.sections,
120 }));
121 results.push(...sections);
122 });
123 return results;
124 });
125
126 return pages.map((props: Props) => {
127 return {params: { section: props.slug }, props };
128 });
129}
130
131const makePaginationLinks = () => {
132 const index = otherSections.findIndex(section => section.name === title);
133 const previousSection = index > 0 ? otherSections[index - 1].name : null;
134 const nextSection = index < otherSections.length - 1 ? otherSections[index + 1].name : null;
135 return { previous: previousSection, next: nextSection };
136};
137
138const { previous, next } = makePaginationLinks();
139
140---
141
142<Layout
143 title={makePageTitle()}
144 keywords={makeKeyWordTag()}
145 description={makeDescriptionTag()}
146 breadcrumbs={makeBreadcrumbs()}
147 customSchemaJson={makeCarasolData()}
148>
149 <Main>
150
151 <div class="breadcrumbs">
152 <span>
153 <a href="/">Awesome Privacy</a>
154 ➔ <a href={`/${slugify(categoryName)}`}>{categoryName}</a>
155 ➔ <a href={`/${slugify(categoryName)}/${slugify(title)}`}>{title}</a>
156 </span>
157 </div>
158
159 <h2>{title}</h2>
160
161 {intro && (
162 <section class="intro">
163 <p set:html={parseMarkdown(intro)}></p>
164 </section>
165 )}
166
167 <ServiceList services={services} sectionName={title} categoryName={categoryName} />
168
169 <details class="about-this-page">
170 <summary>Objective of this page</summary>
171 <p>
172 Find the best free, open source, E2E encrypted and private alternative to
173 {(alternativeTo || []).map((alt) => (<span>{alt}, </span>))} now.
174 </p>
175 <p>
176 Compare {(services || []).map((serv) => (<span>{serv.name} vs </span>))}
177 </p>
178 <p>
179 Discover the best {title} tools for Android, iPhone, Linux, PC and Chrome to download now.
180 And choose secure, self-hosted, peer-to-peer and independant alternatives in 2024
181 </p>
182 <p>
183 <b>Stop the invasion of privacy from big tech, improve data security stay safe.</b>
184 </p>
185 </details>
186
187
188 {notableMentions && (
189 <section class="notable-mentions">
190 <h3>Notable Mentions</h3>
191 { Array.isArray(notableMentions) ?
192 <ul>
193 {notableMentions.map((mention) => (
194 <li>
195 <a href={mention.url}>{mention.name}</a>
196 {mention.description && (
197 <span>- </span>
198 <span set:html={parseMarkdown(mention.description)}></span>
199 )}
200 </li>
201 ))}
202 </ul> :
203 <p set:html={parseMarkdown(notableMentions)}></p>
204 }
205 </section>
206 )}
207
208 {furtherInfo && (
209 <section class="further-info">
210 <h3>Notes</h3>
211 <p set:html={parseMarkdown(furtherInfo)}></p>
212 </section>
213 )}
214
215 {wordOfWarning && (
216 <section class="word-of-warning">
217 <h3>Word of Warning</h3>
218 <p set:html={parseMarkdown(wordOfWarning)}></p>
219 </section>
220 )}
221
222 {services.length > 0 && (<section class="submit-alternative">
223 <h3>Submit New Entry</h3>
224 <p>
225 Are we missing anything?
226 You can help us improve this page, by <a href="/submit">submitting a new entry</a>
227 </p>
228 </section>
229 )}
230
231 <div class="pagination-navigation">
232 { previous ? (
233 <Button url={`/${slugify(categoryName)}/${slugify(previous)}`}>
234 <span>← Previous</span>
235 <p>{previous}</p>
236 </Button>
237 ) : <p class="nothing"></p>}
238 <a href={`/${slugify(categoryName)}`} class="go-to-category">
239 View all in {categoryName} ({otherSections.length})
240 </a>
241 { next && (
242 <Button url={`/${slugify(categoryName)}/${slugify(next)}`}>
243 <span>Next →</span>
244 <p>{next}</p>
245 </Button>
246 )}
247 </div>
248 </Main>
249</Layout>
250
251<style lang="scss">
252
253section {
254 padding-bottom: var(--space-md);
255 &:not(:last-child) {
256 border-bottom: 2px solid var(--accent-3);
257 }
258}
259
260h2 {
261 font-size: var(--text-3xl);
262 margin: -2rem 0 var(--space-lg) -2rem;
263 box-shadow: var(--shadow-lg);
264 background: var(--accent);
265 color: var(--accent-fg);
266 width: fit-content;
267 padding: var(--space-xs) var(--space-sm);
268 }
269
270
271.intro {
272 font-style: italic;
273 opacity: var(--opacity-soft);
274}
275
276
277.about-this-page {
278 summary {
279 display: none;
280 }
281 font-size: var(--text-sm);
282 opacity: var(--opacity-soft);
283}
284
285
286</style>